package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Role;
import com.qk.entity.dto.role.RoleDTO;
import com.qk.management.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author fantuan
 * @created 2025/10/8 11:41
 * @description
 */
@RestController
@RequestMapping("/roles")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @PutMapping
    public Result updateRole(@RequestBody Role role) {
        roleService.update(role);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getRoleById(@PathVariable Integer id) {
        Role role = roleService.getRoleById(id);
        return Result.success(role);
    }

    @PostMapping
    public Result addRole(@RequestBody Role role) {
        roleService.add(role);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteRole(@PathVariable Integer id) {
        roleService.deleteById(id);
        return Result.success();
    }

    @GetMapping
    public Result page(RoleDTO dto){
        PageResult<Role> pageResult = roleService.page(dto);
        return Result.success(pageResult);
    }
    @GetMapping("/list")
    public Result list() {
        return Result.success(roleService.list());
    }
}
